package models.admin;

import models.BaseModel;
import models.merchant.Merchant;

import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import java.util.List;

/**
 * Created by liming on 16/7/2.
 */
@Entity
@Table(name = "admin_user_merchant")
public class AdminUserMerchant extends BaseModel {
    @ManyToOne
    @JoinColumn(name = "admin_user_id")
    public AdminUser adminUser;

    @ManyToOne
    @JoinColumn(name = "merchant_id")
    public Merchant merchant;

    /**
     * 删除管理商户
     *
     * @param userId
     */
    public static void deleteByUserId(long userId) {
        AdminUserMerchant.delete("adminUser.id=?", userId);
    }

    /**
     * 查询用户管理商户
     *
     * @param userId
     */
    public static List<AdminUserMerchant> findByUserId(long userId) {
        return AdminUserMerchant.find("adminUser.id=?", userId).fetch();
    }
}
